package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.Article;
import com.czh.springboot04.mapper.ArticleMapper;
import com.czh.springboot04.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public int addArticle(Article article) {
        return articleMapper.insertArticle(article);
    }

    @Override
    public int deleteArticle(int id) {
        return articleMapper.deleteArticle(id);
    }

    @Override
    public int deleteArticles(int[] ids) {
        return articleMapper.deleteArticles(ids);
    }

    @Override
    public int updateA(Article article) {
        return articleMapper.updateA(article);
    }

    @Override
    public Article findById(int id) {
        return articleMapper.findById(id);
    }

    @Override
    public PageInfo<Article> selectAllInPage(int pageNum,int pageSize,Article article) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> articles = articleMapper.selectAll(article);
        return new PageInfo<>(articles);
    }
}
